package com.zsoft.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zsoft.domain.TopicDomain;
import com.zsoft.domain.TopicTypeDomain;
import com.zsoft.service.TopicService;
import com.zsoft.service.TopicTypeService;

@Controller(value = "topic")
@RequestMapping(value = "/topic")
public class TopicManageController {
	@Autowired
	private TopicTypeService typeService;
	@Autowired
	private TopicService topicService;

	@RequestMapping(value = "/fck.htm")
	public ModelAndView fck(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("fck/demo");

		return mv;
	}

	@RequestMapping(value = "/add.htm")
	public ModelAndView addTopic(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("topic/addTopic");
		List<TopicTypeDomain> typeList = typeService.findList(null);
		mv.addObject("typeList", typeList);
		return mv;
	}

	// 发帖子以后提交的方法
	@RequestMapping(value = "/submit.htm")
	public ModelAndView submitTopic(TopicDomain topic, HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("topic/succ");
		topicService.add(topic);
		return mv;
	}

	@RequestMapping(value = "/edit.htm")
	public ModelAndView editTopic(HttpServletRequest request, HttpServletResponse response) {

		ModelAndView mv = new ModelAndView("topic/editTopic");
		return mv;
	}

	@RequestMapping(value = "/list.htm")
	public ModelAndView listTopic(HttpServletRequest request, HttpServletResponse response) {

		ModelAndView mv = new ModelAndView("topic/listTopic");
		// 获取帖子列表
		List<TopicDomain> topicList = topicService.findList(null);
		mv.addObject("topicList", topicList);
		return mv;
	}
}
